package com.xbongbong.app.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.business.WorkReportDailyEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Author mingliang
 * @Description 工作报告导出枚举
 * @Date 2022/3/30 19:02
 **/
@Getter
public enum DailyWorkExcelEnum {
    /**
     * 字段
     */
    TYPE("type", WorkReportDailyEnum.TYPE.getAttrName(), 1, 1),
    DATE("date", WorkReportDailyEnum.REPORT_DATE.getAttrName(), 1, 2),
    SHOULD_SENT("shouldSent", "enum.workReportDaily.all.report", 0, 3),
    SHOULD_REPORT("realSent", "enum.workReportDaily.should.report", 0, 4),
    NO_REPORT("noSent", "enum.workReportDaily.no.report", 0, 5),
    NO_SUBMIT("noSubmit", "enum.workReportDaily.overdue.report.staff", 0, 6),
    HAVE_SUBMIT("haveSubmit", "enum.workReportDaily.receive.report.staff", 0, 7);

    /**
     * 别名
     */
    private final String alias;
    /**
     * 名称
     */
    private final String name;
    /**
     * 是否必填 1:必填 0：选填
     */
    private final Integer required;

    /**
     * 排序字段
     */
    private final Integer sort;


    DailyWorkExcelEnum(String alias, String name, Integer required, Integer sort) {
        this.alias = alias;
        this.name = name;
        this.required = required;
        this.sort = sort;
    }

    public static List<DailyWorkExcelEnum> getAllEnum() {
        return new ArrayList<>(Arrays.asList(values()));
    }

    public static Map<String, String> getAllEnumMap() {
        Map<String, String> map = new HashMap<>();
        DailyWorkExcelEnum[] values = values();
        for (int i = 0; i < values.length; i++) {
            map.put(values[i].getAlias(), values[i].getName());
        }
        return map;
    }

    public static Map<String, Integer> getAllEnumSort() {
        Map<String, Integer> map = new HashMap<>();
        DailyWorkExcelEnum[] values = values();
        for (int i = 0; i < values.length; i++) {
            map.put(values[i].getAlias(), values[i].getSort());
        }
        return map;
    }

    public static DailyWorkExcelEnum getByName(String code) {
        for (DailyWorkExcelEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getName())) {
                return cacheCode;
            }
        }
        return null;
    }

    public String getName() {
        if (Objects.equals(DailyWorkExcelEnum.DATE.getAlias(), alias) || Objects.equals(DailyWorkExcelEnum.TYPE.getAlias(), alias)) {
            return I18nMessageUtil.getMessage(name) + "*";
        } else {
            return I18nMessageUtil.getMessage(name);
        }
    }
}
